package educational.cad.model;

/**
 * This class represents a physical entity of a wire.
 * 
 * @author Sergey Seroshtan
 * 
 */
public final class Wire {

	public Wire(Package source, Pin sourcePin, Package target, Pin targetPin) {

		if (source == null) {
			throw new IllegalArgumentException("Source package is undefined.");
		}
		if (sourcePin == null) {
			throw new IllegalArgumentException("Source pin is undefined.");
		}
		if (target == null) {
			throw new IllegalArgumentException("Target package is undefined.");
		}
		if (targetPin == null) {
			throw new IllegalArgumentException("Target pin is undefined.");
		}
		this.source = source;
		this.sourcePin = sourcePin;
		this.target = target;
		this.targetPin = targetPin;
	}

	public Package source() {
		return source;
	}

	public Pin sourcePin() {
		return sourcePin;
	}

	public Package target() {
		return target;
	}

	public Pin targetPin() {
		return targetPin;
	}

	private final Package source;
	private final Pin sourcePin;

	private final Package target;
	private final Pin targetPin;

	@Override
	public boolean equals(Object another) {
		final Wire anotherWire = (Wire) another;
		return this.source == anotherWire.source && this.sourcePin == anotherWire.sourcePin
				&& this.target == anotherWire.target && this.targetPin == anotherWire.targetPin;
	}

	@Override
	public int hashCode() {
		int hash = 17;
		hash = 31 * hash + source.hashCode();
		hash = 31 * hash + sourcePin.hashCode();
		hash = 31 * hash + target.hashCode();
		hash = 31 * hash + targetPin.hashCode();
		return hash;
		
	}

}
